﻿using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using Uber.Core.Service;
using Uber.Infra;

namespace Uber.WebUI.Models
{
    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
    public sealed class EmailUniqueAttribute : ValidationAttribute
    {
        private const string DefaultErrorMessage = "email already in use";

        public EmailUniqueAttribute()
            : base(DefaultErrorMessage)
        {
        }

        public override string FormatErrorMessage(string name)
        {
            return DefaultErrorMessage;
        }

        public override bool IsValid(object value)
        {
            return string.IsNullOrEmpty((string)value) || !IoC.Resolve<IAccounts>().EmailExists((string)value);
        }
    }

    public class ProfileEditInput
    {
        public string Email { get; set; }

        [DisplayName("Secondary email")]
        [RegularExpression(@"[\w0-9._%+-]+@[\w0-9.-]+.\w{2,4}", ErrorMessage = "Incorrect email")]
        [StringLength(100)]
        public string Aemail { get; set; }

        [Required]
        [StringLength(30)]
        public string DisplayName { get; set; }
    }

    public class EditQuestionInput : AskQuestionInput
    {
        public long Id { get; set; }
    }

    public class AddCommentInput
    {
        public long Id { get; set; }

        [Required]
        [StringLength(600,MinimumLength = 15)]
        public string Body { get; set; }
    }

    public class EditPostInput
    {
        public long Id { get; set; }

        
        public string Title { get; set; }

        [Required]
        [StringLength(30000, MinimumLength = 30)]
        public string Body { get; set; }

        public long ParentId { get; set; }
    }

    public class AskQuestionInput
    {
        [Required]
        [StringLength(150,MinimumLength = 15)]
        [AllowHtml]
        public string Title { get; set; }

        [Required]
        [StringLength(30000, MinimumLength = 30)]
        [AllowHtml]
        public string Body { get; set; }
    }

    public class ContactUsInput
    {
        [Required]
        [RegularExpression(@"[\w0-9._%+-]+@[\w0-9.-]+.\w{2,4}", ErrorMessage = "Incorrect email")]
        [StringLength(100)]
        public string Email { get; set; }

        [Required]
        [StringLength(30)]
        public string Subject { get; set; }

        [Required]
        [StringLength(700, MinimumLength = 10)]
        public string Message { get; set; }
    }

    public class AccountInput
    {
        [Required]
        [RegularExpression(@"[\w0-9._%+-]+@[\w0-9.-]+.\w{2,4}", ErrorMessage = "Incorrect email")]
        [StringLength(100)]
        [EmailUnique]
        public string Email { get; set; }

        [StringLength(30)]
        public string DisplayName { get; set; }

        [Required]
        [StringLength(20)]
        public string Password { get; set; }

        [Required(ErrorMessage = "Please re-enter your password")]
        [StringLength(20)]
        public string ConfirmPassword { get; set; }
    }
}


